package com.sky.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.support.collections.RedisCollectionFactoryBean;

@Configuration
@Slf4j
public class RedisConfiguration {

    // 创建一个 RedisConnectionFactory 类型的 Bean，名称为 redisConnectionFactory
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory ){
        // 创建一个 RedisTemplate 类型的 Bean
        RedisTemplate redisTemplate=new RedisTemplate();
        // 设置redis的连接工厂对象
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        // 设置 keySerializer 为 StringRedisSerializer，用于将键值序列化
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        // 返回 redisTemplate
        return redisTemplate;


    }
}
    //@Bean
    //public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
    //    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
    //    redisTemplate.setConnectionFactory(redisConnectionFactory);
    //    redisTemplate.setKeySerializer(new StringRedisSerializer());
    //    redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
    //    return redisTemplate;



